package com.xbongbong.parent.explain;

import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.parent.abstracts.AbstractFormExplainHandleName;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainDTO;
import com.xbongbong.pro.formexplain.pojo.vo.HandlerExplainVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: wufeng
 * @date: 2018/11/2 10:29
 * @desrcption: 表单数据详情，编辑，新建的时候获取字段回显名称，以及过滤不可见字段
 */
@Component
public class FormDataFormExplainHandleName extends AbstractFormExplainHandleName {

    private static final Logger LOG = LoggerFactory.getLogger(FormDataFormExplainHandleName.class);

    @Override
    public HandlerExplainVO handleExplain(HandlerExplainDTO handlerExplainDTO) throws XbbException {
        HandlerExplainVO handlerExplainVO;
        try {
            List<FieldAttrEntity> explainList = handlerExplainDTO.getExplainList();
            handlerExplainVO = getExplainList(explainList, handlerExplainDTO);
            handleExplainDefaultLimit(handlerExplainVO, handlerExplainDTO);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("FormDataFormExplainHandleName.handleExplain处理字段中的部门、角色、用户等名称报错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return handlerExplainVO;
    }

}
